package battle_grpc

import (
	"battle-server/manager"
	"context"
	pb "pb/proto"
)

type BattleGrpcService struct {
	pb.UnimplementedBattleGrpcServiceServer
}

func (b *BattleGrpcService) SyncToken(ctx context.Context, req *pb.GrpcBattleTokenSyncReq) (*pb.GrpcBattleTokenSyncRes, error) {
	token := req.Token
	// todo 验证格式
	err := manager.AddTokenToCache(token)
	if err != nil {
		return &pb.GrpcBattleTokenSyncRes{State: 0}, err
	}
	return &pb.GrpcBattleTokenSyncRes{State: 1}, nil
}
